package com.njlime.sys.repository;

import com.njlime.core.base.repository.impl.BaseDaoImpl;
import com.njlime.sys.entities.ConfigItem;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class ConfigItemDaoImpl extends BaseDaoImpl<ConfigItem> {
	Logger logger = Logger.getLogger(ConfigItemDaoImpl.class);

    /**
     * 删除
     * @param unit_id
     */
    public void deleteByUnit(Integer unit_id){
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("delete from t_config_item where unit_id = ? ");
        arrList.add(unit_id);
        updateJdbc(sb.toString(),arrList);
    }

    /**
     * 根据配置名称获取配置项
     * @param config_name
     * @param unit_id
     * @return
     */
	public ConfigItem getByName(String config_name, Integer unit_id){
		StringBuilder sb = new StringBuilder();
		List<Object> arrList = new ArrayList<Object>();
		sb.append(" select * ");
		sb.append(" from t_config_item ");
		sb.append(" where config_name = ? and unit_id = ? ");
		arrList.add(config_name);
		arrList.add(unit_id);
        return findOne(sb.toString(), arrList);
	}

    /**
     * 根据配置名称修改配置项的值
     * @param config_name
     * @param config_value
     * @param unit_id
     * @return
     */
	public int updateByName(String config_name, String config_value, Integer unit_id){
		StringBuilder sb = new StringBuilder();
		List<Object> arrList = new ArrayList<Object>();
		sb.append(" update t_config_item set ");
		sb.append(" config_value = ? ");
		sb.append(" where config_name = ? and unit_id = ? ");
		arrList.add(config_value);
		arrList.add(config_name);
        arrList.add(unit_id);
		return updateJdbc(sb.toString(),arrList);
	}

}
